/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlets.javabeans;

import fr.charlesen.projets.utt.lo09.entites.Etudiants;
import fr.charlesen.projets.utt.lo09.entites.Stages;
import fr.charlesen.projets.utt.lo09.facades.EtudiantsFacadeLocal;
import fr.charlesen.projets.utt.lo09.facades.StagesFacadeLocal;
import fr.charlesen.projets.utt.lo09.sessionBeans.ProgrammeBossLocal;
import fr.charlesen.projets.utt.lo09.sessionBeans.ResponsableDesStagesLocal;
import fr.charlesen.projets.utt.lo09.sessionBeans.ServiceDesStagesLocal;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Charles EDOU NZE
 */
@ManagedBean(name = "stages")
@RequestScoped
public class StagesBeans {

    @EJB
    private ProgrammeBossLocal prog;
    @EJB
    private ServiceDesStagesLocal stageBS;
    @EJB
    private ResponsableDesStagesLocal respStageBS;
    private EtudiantsFacadeLocal etudiantFacade;
    private StagesFacadeLocal stageFacade;
    private List<Etudiants> listEtudiants;
    private List<Stages> listStages;
    private Stages stage;
    private Etudiants etudiant;

    /** Creates a new instance of StagesBeans */
    public StagesBeans() {
        setStages(new Stages());
        setEtudiant(new Etudiants());
    }

    public Etudiants getEtudiant() {
        return etudiant;
    }

    public void setEtudiant(Etudiants etudiant) {
        this.etudiant = etudiant;
    }

    public Stages getStages() {
        return stage;
    }

    public void setStages(Stages stages) {
        this.stage = stages;
    }

    public List<Etudiants> getListEtudiants() {
        listEtudiants = prog.listEtu();
        return listEtudiants;
    }

    public void setListEtudiants(List<Etudiants> listEtudiants) {
        this.listEtudiants = listEtudiants;
    }

    public List<Stages> getListStages() {
        listStages = stageBS.listStages();
        return listStages;
    }

    public void setListStages(List<Stages> listStages) {
        this.listStages = listStages;
    }

    public String doAddStage() {

        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        HttpServletRequest request = (HttpServletRequest) ec.getRequest();
        String type = request.getParameter("type");
        String sujet = request.getParameter("sujet");
        String entreprise = request.getParameter("entreprise");
        String ville = request.getParameter("ville");
        String pays = request.getParameter("pays");

        stageBS.addStage(type, sujet, entreprise, ville, pays);
        /*
        etudiant.setId(prog.getTotalEtu() + 2);
        etudiant.setAutorisation(0);
        etudiant.setNom(nom);
        etudiant.setPrenom(prenom);
        prog.addEtu(etudiant);
         */
        return "indexStages.xhtml";
    }

    public String doDelStage() {
        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        HttpServletRequest request = (HttpServletRequest) ec.getRequest();
        int idStage = Integer.parseInt(request.getParameter("id"));
        stageBS.delStage(idStage);
        return "indexStages.xhtml";
    }

    public String doAssignStage() {
        return "pages/assignStage.xhtml";
    }

    public String doAssignBack() {
        /*
        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        HttpServletRequest request = (HttpServletRequest) ec.getRequest();
        
         * On récupère l'ID de l'étudiant afin d'afficher son nom dans le message :
         * "Assigner un suiveur à l'étudiant : Nom_De_L_Etudiant "
         * int idEtu = Integer.parseInt(request.getParameter("idEtu"));
         * request.setAttribute("NomEtu", prog.listEtuData(idEtu).getNom() + " " + prog.listEtuData(idEtu).getPrenom());
         * request.setAttribute("idEtudiant", idEtu);
         *
         */
        //etudiantsStageAss
        //int idStage = Integer.parseInt(request.getParameter("stageAss"));
        //int idEtudiant = Integer.parseInt(request.getParameter("etudiantsStageAss"));

        //respStageBS.attribStage(etudiantFacade.count(), stageFacade.count());
        //etudiantFacade.find(etudiantFacade.count()).setIdStage(stageFacade.find(stageFacade.count()));
        return "../indexStages.xhtml";
    }
}
